import {createApp} from 'vue'
import App from './App.vue'
import router from './router'
import 'highlight.js/styles/github.css'
import {library} from '@fortawesome/fontawesome-svg-core'
import {fab} from '@fortawesome/free-brands-svg-icons'
import {fas} from '@fortawesome/free-solid-svg-icons'
import {far} from '@fortawesome/free-regular-svg-icons'
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome'

// 添加所有图标到库
library.add(fab, fas, far)

// 创建Vue应用
const app = createApp(App)

// 注册全局组件
app.component('font-awesome-icon', FontAwesomeIcon)

// 全局错误处理
const setupErrorHandlers = (app) => {
    app.config.errorHandler = (err, vm, info) => {
        console.error('Vue Error:', err)
        console.error('Error Info:', info)
    }

    window.addEventListener('unhandledrejection', (event) => {
        console.error('Unhandled Promise Rejection:', event.reason)
    })

    window.onerror = (message, source, lineno, colno, error) => {
        console.error('Global Error:', {
            message,
            source,
            lineno,
            colno,
            error
        })
    }
}

// 设置错误处理
setupErrorHandlers(app)

// 使用路由
app.use(router)

// 挂载应用
app.mount('#app')
